package cn.newhopedairy.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * Swagger 配置，升级到swagger3
 *
 * 注：@EnableSwagger2注解须放在Application上，放在这里不起作用是因为componentScan没扫描到，修改扫描路径即可。
 *
 * @author Neo.Li
 * @date 2020-09-09 18:05
 */
@Configuration
@EnableOpenApi
public class SwaggerConfig {
    @Bean
    public Docket swaggerRestApi() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(new ApiInfoBuilder()
                        .title("FreshGo API")
                        .description("FreshGo DDD project API document.")
                        .termsOfServiceUrl("")
                        .contact(new Contact("Neo Li", "", "liyaozong233@hotmail.com"))
                        .version("1.0")
                        .build())
                .enable(true)
                .select()
                // Swagger扫描路径，向上一级支持多包多个服务
                .apis(RequestHandlerSelectors.basePackage("cn.newhopedairy"))
                .paths(PathSelectors.any())
                .build();
    }
}
